package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.util.ExcelFormatUtil;
import cn.stylefeng.guns.sys.core.util.UUIDUtils;
import cn.stylefeng.guns.sys.modular.system.controller.BaseFrontController;
import cn.stylefeng.guns.sys.modular.system.entity.AttendAuditBtyArchives;
import cn.stylefeng.guns.sys.modular.system.entity.BtyPerformanceMonthCheck;
import cn.stylefeng.guns.sys.modular.system.entity.BtyPerformanceMonthInformation;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.DelFlagEnum;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyPerformanceMonthInformationMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.*;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyDdpageByAccountTime;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyPerformanceMonthInformationResult;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyPerformanceSelectResult;
import cn.stylefeng.guns.sys.modular.system.service.AttendAuditBtyArchivesService;
import cn.stylefeng.guns.sys.modular.system.service.BtyPerformanceMonthCheckService;
import cn.stylefeng.guns.sys.modular.system.service.BtyPerformanceMonthInformationService;
import cn.stylefeng.guns.sys.modular.system.service.BtyPerformancePointService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wjk
 * @since 2022-02-10
 */
@Service
public class BtyPerformanceMonthInformationServiceImpl extends ServiceImpl<BtyPerformanceMonthInformationMapper, BtyPerformanceMonthInformation> implements BtyPerformanceMonthInformationService {

    private static final Logger logger = LoggerFactory.getLogger(BtyPerformanceMonthInformationServiceImpl.class);
    /**
     * 绩效审核服务类
     */
    @Autowired
    private BtyPerformanceMonthCheckService btyPerformanceMonthCheckService;


    @Autowired
    private AttendAuditBtyArchivesService attendAuditBtyArchivesService;

    @Autowired
    protected BtyPerformancePointService btyPerformancePointService;

    @Override
    public void add(BtyPerformanceMonthInformationParam param) {
        BtyPerformanceMonthInformation entity = getEntity(param);
        this.save(entity);
    }


    @Override
    public void delete(BtyPerformanceMonthInformationParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyPerformanceMonthInformationParam param) {
        BtyPerformanceMonthInformation oldEntity = getOldEntity(param);
        BtyPerformanceMonthInformation newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyPerformanceMonthInformationResult findBySpec(BtyPerformanceMonthInformationParam param) {
        return null;
    }

    @Override
    public List<BtyPerformanceMonthInformationResult> findListBySpec(BtyPerformanceMonthInformationParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyPerformanceMonthInformationParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    /***
     * 点击编辑占比保存
     * @param account
     * @param param
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String,String> updateZb(String account, BtyPerformanceMonthInformationParam param) {
        Map<String,String> map = new HashMap<String,String>();

        // 根据用户手机号，和店面的妖码，还有当前时间，验证当前用户是否有操作此店本月绩效的权限
        BtyPerformanceMonthPermissionsParam permissionsParam = new BtyPerformanceMonthPermissionsParam();
        permissionsParam.setAccount(account);
        permissionsParam.setYaoma(param.getYaoma());

        Map<String,String> mapPermissions = this.btyPerformanceMonthCheckService.BtyPerformanceMonthPermissionsValidation(permissionsParam);
        if(mapPermissions.get("permissionsValid").equals("false")){
            map.put("flag","false");
            map.put("message",mapPermissions.get("permissionsInfo"));
            map.put("data","");
            return map;
        }

        BtyPerformanceMonthInformation newEntity = getEntity(param);

        BtyPerformanceMonthInformation oldEntity = getOldEntity(param);

        if(ToolUtil.isEmpty(oldEntity)||ToolUtil.isEmpty(oldEntity.getId())){
            map.put("flag","false");
            map.put("message","在带编辑绩效人员中，未查询到此人员信息，请确认是否创建了此条绩效审核信息，或已经被提交。");
            map.put("data","");
            return map;
        }


        Map<String,String> mapTime = this.btyPerformanceMonthCheckService.getPerformanceDay();

        // 根据妖码，和时间，查询这个店的信息
        BtyPerformanceReceiveParam ReceiveParam = new BtyPerformanceReceiveParam();
        ReceiveParam.setYaoma(oldEntity.getYaoma());
        ReceiveParam.setTime(mapTime.get("lastYearMonth"));

        BtyDdpageByAccountTime btyDdpageByAccountTime = btyPerformanceMonthCheckService.getBtyDdpageByYaomaTime(ReceiveParam);

        if (ToolUtil.isEmpty(btyDdpageByAccountTime.getCl())) {
            BigDecimal num = btyDdpageByAccountTime.getCl();
            int i = num.compareTo(BigDecimal.ZERO);
            if (i == -1) {
                map.put("flag","false");
                map.put("message","此店在[" + ReceiveParam.getTime() + "]月，纯利小于零，无需创建绩效提交信息。");
                map.put("data","");
                return map;
            }
            if (i == 0) {
                map.put("flag","false");
                map.put("message","此店在[" + ReceiveParam.getTime() + "]月，纯利等于零，无需创建绩效提交信息。");
                map.put("data","");
                return map;
            }
            if (i == 1) {
                // i大于0 的
            }
        }

        //  判断此用户是否有此店的权限
        // 默认没有该店的权限
        Map<String,String> mapIdentity = this.btyPerformanceMonthCheckService.checkIdentity(account);
        Boolean flagNotHaveShopIdentity = true;
        if (ToolUtil.isNotEmpty(mapIdentity.get("userZwAllStr"))) {
            if (mapIdentity.get("userZwAllStr").indexOf("督导") > -1 &&ToolUtil.isNotEmpty(btyDdpageByAccountTime.getDddh()) && btyDdpageByAccountTime.getDddh().equals(account)) {
                flagNotHaveShopIdentity = false;
            }

            if (mapIdentity.get("userZwAllStr").indexOf("大店长") > -1 &&ToolUtil.isNotEmpty(btyDdpageByAccountTime.getDh()) && btyDdpageByAccountTime.getDh().equals(account)) {
                flagNotHaveShopIdentity = false;
            }
        }
        // 若没有本店权限，返回空
        if (flagNotHaveShopIdentity) {
            map.put("flag","false");
            map.put("message","当前登录用户没有创建或者编辑该店绩效的权限，请确认后操作。");
            map.put("data","");
            return map;
        }

        //不能更改的参数校验
        // 若是之前在本店做过绩效的运营经理或者督导，不允许修改绩效点数
        //2022-02-15 需求变动，新老数据都可以被修改
//        if(String.valueOf(oldEntity.getLastFlag()).equals("0")){
//            if (oldEntity.getZw().indexOf("督导") > -1) {
//                return ResponseData.error(200,"督导职位不可修改绩效点数。",false);
//            }
//            if (oldEntity.getZw().indexOf("营运经理") > -1) {
//                return ResponseData.error(200,"营运经理职位不可修改绩效点数。",false);
//            }
//        }

        if (ObjectUtil.isEmpty(newEntity.getRatio())) {
            newEntity.setRatio(new BigDecimal("0"));
        }


        Boolean flag = this.baseMapper.updateZb(param);
        if(flag){
            // 若没有本店权限，返回空
            map.put("flag","true");
            map.put("message","修改成功。");
            map.put("data","");
            return map;
        }
        // 若没有本店权限，返回空
        map.put("flag","false");
        map.put("message","修改失败。");
        map.put("data","");
        return map;
    }

    @Override
    public Map<String,String> delPersonzb(String account, BtyPerformanceMonthInformationParam param) {
        Map<String,String> map = new HashMap<String, String>();

        // 根据用户手机号，和店面的妖码，还有当前时间，验证当前用户是否有操作此店本月绩效的权限
        BtyPerformanceMonthPermissionsParam permissionsParam = new BtyPerformanceMonthPermissionsParam();
        permissionsParam.setAccount(account);
        permissionsParam.setYaoma(param.getYaoma());

        Map<String,String> mapPermissions = this.btyPerformanceMonthCheckService.BtyPerformanceMonthPermissionsValidation(permissionsParam);
        if(mapPermissions.get("permissionsValid").equals("false")){
            map.put("flag","false");
            map.put("message",mapPermissions.get("permissionsInfo"));
            map.put("data","");
            return map;
        }

        //参数判断,标记删除
        if (ObjectUtil.isEmpty(param.getId())) {
            map.put("flag","false");
            map.put("message","id不能为空");
            map.put("data","");
            return map;
        }

        BtyPerformanceMonthInformation oldEntity = getOldEntity(param);
        //参数判断,标记删除
        if (ObjectUtil.isEmpty(oldEntity)||ObjectUtil.isEmpty(oldEntity.getId())) {
            map.put("flag","false");
            map.put("message","在带编辑绩效人员中，未查询到此人员信息，请确认是否创建了此条绩效审核信息，或已经被提交。");
            map.put("data","");
            return map;
        }

        oldEntity.setDelFlag(DelFlagEnum.YES.getCode());
        Boolean flag = this.updateById(oldEntity);
        //参数判断,标记删除
        if (flag) {
            map.put("flag","true");
            map.put("message","修改成功。");
            map.put("data","");
            return map;
        }
        map.put("flag","true");
        map.put("message","修改成功。");
        map.put("data","");
        return map;
    }


    /**
     * 根据 CheckId 获取 月度绩效详情信息;
     *
     * @param checkId
     * @return
     */
    @Override
    public List<BtyPerformanceMonthInformation> getBtyPerformanceMonthInformationListPageByCheckId(Long checkId) {
        BtyPerformanceMonthInformationParam param = new BtyPerformanceMonthInformationParam();
        param.setBtyPerformanceMonthCheckId(checkId);
        List<BtyPerformanceMonthInformation> list = this.baseMapper.getBtyPerformanceMonthInformationListPageByCheckId(param);
        return list;
    }


    /**
     * 根据 CheckId 获取 月度绩效详情信息，包含被驳回的原因
     *
     * @author wjk
     * @Date 2022-04-06
     */
    @Override
    public List<BtyPerformanceMonthInformationResult> getBtyPerformanceMonthInformationListDismissedByCheckId(Long checkId) {
        BtyPerformanceMonthInformationParam param = new BtyPerformanceMonthInformationParam();
        param.setBtyPerformanceMonthCheckId(checkId);
        List<BtyPerformanceMonthInformationResult> list = this.baseMapper.getBtyPerformanceMonthInformationListDismissedByCheckId(param);
        return list;
    }


    /**
     * 根据店妖码，查询上个月的绩效信息
     *
     * @author wjk
     * @Date 2022-02-14
     */
    @Override
    public List<BtyPerformanceMonthInformation> getBtyPerformanceMonthInformation(BtyPerformanceReceiveParam param) {
        List<BtyPerformanceMonthInformation> list = this.baseMapper.getBtyPerformanceMonthInformation(param);
        return list;
    }

    /**
     * 批量保存
     *
     * @author wjk
     * @Date 2022-02-14
     */
    @Override
    public int saveList(List<BtyPerformanceMonthInformation> list) {
        //批量增加
        int size = simpleSqlInsertBatch(list);
        return size;
    }

    /**
     * mysql的批量插入方式，oracle不支持。
     * AttendEmployeeMonth批量增加月度员工考勤表
     *
     * @param list
     */
    public int simpleSqlInsertBatch(List<BtyPerformanceMonthInformation> list) {
        if (list == null || list.size() < 1) {
            return 0;
        }
        // 如果提交的列表条数小于提交阀值
        List<BtyPerformanceMonthInformation>[] splitLists = splitLists(list, 5000);
        for (List<BtyPerformanceMonthInformation> tempList : splitLists) {
            this.baseMapper.addList(tempList);
        }
        return list.size();
    }


    /**
     * 对一个列表按照splitNum进行分割。
     *
     * @param lists
     * @param splitNum
     * @param <T>
     * @return
     */
    public static <T> List<BtyPerformanceMonthInformation>[] splitLists(List<BtyPerformanceMonthInformation> lists, int splitNum) {
        int listSize;
        if (lists == null || (listSize = lists.size()) < 1) {
            return new ArrayList[0];
        }
        int length = listSize % splitNum == 0 ? listSize / splitNum : listSize / splitNum + 1;
        // 这里面如果用ArrayList，会在50行报错。ArrayList list = new List();这样会报错。
        List<BtyPerformanceMonthInformation>[] results = new List[length];
        int fromIndex, toIndex;
        for (int i = 0; i < length; i++) {
            fromIndex = i * splitNum;
            toIndex = (fromIndex + splitNum) > listSize ? listSize : (fromIndex + splitNum);
            results[i] = lists.subList(fromIndex, toIndex);
        }
        return results;
    }

    @Override
    public LayuiPageInfo findPageXm(BtyPerformanceMonthInformationParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageListXm(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public LayuiPageInfo findPageYyjl(BtyPerformanceMonthInformationParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageListYyjl(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageDd(AttendAuditBtyAreaParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageListDd(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<BtyPerformanceSelectResult> findListDd(AttendAuditBtyAreaParam param) {

        List<BtyPerformanceSelectResult> list = this.baseMapper.customListDd(param);
        return list;
    }


    @Override
    public LayuiPageInfo findPageDm(AttendAuditBtyAreaParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageListDm(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 根据妖码和人员的id 将人员调入本店
     *
     * @author wjk
     * @Date 2021-02-15
     */
    @Override
    public Map<String, String> addArchivesToPerformanceMonth(String account, BtyPerformanceMonthInformationParam param) {
        Map<String, String> map = new HashMap<String, String>();

        // 根据妖码获取，此店上月的绩效考核信息，若没有，则返回空
        // 根据妖码，和时间，查询这个店的信息
        // 判断是否在绩效创建时间

        Map<String, String> mapTime = btyPerformanceMonthCheckService.getPerformanceDay();
        if ("1".equals(mapTime.get("pageValid"))) {
            map.put("flag", "false");
            map.put("message", "不是在绩效提交时间内，不允许编辑或提交绩效信息。" + mapTime.get("pageInfo"));
            map.put("data", "");
            return map;
        }

        BtyPerformanceReceiveParam btyPerformanceReceiveParam = new BtyPerformanceReceiveParam();
        btyPerformanceReceiveParam.setYaoma(param.getYaoma());
        if (ObjectUtil.isEmpty(btyPerformanceReceiveParam.getTime())) {
            btyPerformanceReceiveParam.setTime(mapTime.get("lastYearMonth"));
        }


        BtyDdpageByAccountTime btyDdpageByAccountTime = btyPerformanceMonthCheckService.getBtyDdpageByYaomaTime(btyPerformanceReceiveParam);
        if (ToolUtil.isEmpty(btyDdpageByAccountTime) || ToolUtil.isEmpty(btyDdpageByAccountTime.getId())) {
            map.put("flag", "false");
            map.put("message", "根据未查询到此店信息，请确认此店是否在人事档案数据中建店。");
            map.put("data", "");
            return map;
        }

        if(ToolUtil.isEmpty(btyDdpageByAccountTime.getBtyPerformanceMonthCheckId())){
            map.put("flag","false");
            map.put("message","未查询到此店上月的绩效审核信息，请先进行创建。");
            map.put("data","");
            return map;
        }

        if (ToolUtil.isEmpty(btyDdpageByAccountTime.getCheckStatus()) && btyDdpageByAccountTime.getCheckStatus().equals("1")) {
            map.put("flag", "false");
            map.put("message", "此店上月的绩效审核已提交,若需要修改，请联系人事进行驳回。");
            map.put("data", "");
            return map;
        }


        // 根据人员id 获取此人员的信息，将该人员添加到本店
        AttendAuditBtyArchives attendAuditBtyArchives = attendAuditBtyArchivesService.getById(param.getId());
        if (ToolUtil.isEmpty(attendAuditBtyArchives) || ToolUtil.isEmpty(attendAuditBtyArchives.getId())) {
            map.put("flag", "false");
            map.put("message", "未查询到人员信息。");
            map.put("data", "");
            return map;
        }
        // 判断人员是否在本店，若人员在本店，则修改删除状态信息
        // 根据妖码，月份，编码，查询，此人是否在本店，
        BtyPerformanceMonthInformation  entityParam = new BtyPerformanceMonthInformation();
        entityParam.setBh(attendAuditBtyArchives.getBh());
        entityParam.setYaoma(btyPerformanceReceiveParam.getYaoma());
        entityParam.setMonth(btyPerformanceReceiveParam.getTime());
        BtyPerformanceMonthInformation oldEntity = this.getBtyPerformanceMonthInformationByYaomaMonthBh(entityParam);

        // 若此人已经在本店，并且状态不为删除状态
        if(ToolUtil.isNotEmpty(oldEntity)&&ToolUtil.isNotEmpty(oldEntity.getId())&&String.valueOf(oldEntity.getDelFlag()).equals("0")){
            map.put("flag", "false");
            map.put("message", "此人已在本店，不可重复添加。");
            map.put("data", "");
            return map;
        }

        Boolean flag = false;
        // 若此人已经在本店，做过绩效，状态为删除状态，则修改状态为未被删除
        if(ToolUtil.isNotEmpty(oldEntity)&&ToolUtil.isNotEmpty(oldEntity.getId())&&String.valueOf(oldEntity.getDelFlag()).equals("1")){
            oldEntity.setDelFlag(0);
            oldEntity.setUpdateTime(new Date());
            oldEntity.setUpdateUser(Long.valueOf(account));
            flag = this.updateById(oldEntity);
        }

        // 若此人不在本店，则进行新增人员
        if(ToolUtil.isEmpty(oldEntity)||ToolUtil.isEmpty(oldEntity.getId())){
            // 将人员信息添加到此店的绩效信息
            BtyPerformanceMonthInformation newEntity = new BtyPerformanceMonthInformation();
            Long BtyPerformanceMonthInformationId = UUIDUtils.getId();
            newEntity.setId(BtyPerformanceMonthInformationId);

            newEntity.setBtyPerformanceMonthCheckId(btyDdpageByAccountTime.getBtyPerformanceMonthCheckId());

            newEntity.setDelFlag(0);
            newEntity.setLastFlag(1);
            newEntity.setRatio(new BigDecimal("0"));
            newEntity.setMonth(btyPerformanceReceiveParam.getTime());

            newEntity.setDm(btyDdpageByAccountTime.getDm());
            newEntity.setYaoma(btyPerformanceReceiveParam.getYaoma());
            newEntity.setDd(btyDdpageByAccountTime.getDd());


            newEntity.setBtyPerformanceId(null);
            newEntity.setBtyArchivesId(attendAuditBtyArchives.getId());
            newEntity.setBh(attendAuditBtyArchives.getBh());
            newEntity.setXm(attendAuditBtyArchives.getXm());
            newEntity.setZw(attendAuditBtyArchives.getZw());
            newEntity.setTel(attendAuditBtyArchives.getTel());
            newEntity.setYhk(attendAuditBtyArchives.getYhk());

            newEntity.setCreateTime(new Date());
            newEntity.setCreateUser(Long.valueOf(account));

            flag = this.save(newEntity);
        }

        if(flag){
            map.put("flag","true");
            map.put("message","成功。");
            map.put("data","");
            return map;
        }

        map.put("flag","false");
        map.put("message","本店新增绩效人员失败，请确认人员信息是否正确。");
        map.put("data","");
        return map;
    }


    /**
     * 根据妖码，月份，编码，查询，此人是否在本店
     *
     * @author wjk
     * @Date 2021-02-17
     */
    @Override
    public BtyPerformanceMonthInformation getBtyPerformanceMonthInformationByYaomaMonthBh(BtyPerformanceMonthInformation param) {
        LambdaQueryWrapper<BtyPerformanceMonthInformation> queryWrapper = new LambdaQueryWrapper<BtyPerformanceMonthInformation>();
        queryWrapper.eq(BtyPerformanceMonthInformation::getBh, param.getBh());
        queryWrapper.eq(BtyPerformanceMonthInformation::getYaoma,param.getYaoma());
        queryWrapper.eq(BtyPerformanceMonthInformation::getMonth,param.getMonth());

        List<BtyPerformanceMonthInformation> list = this.list(queryWrapper);
        if(list.size()>0){
            return list.get(0);
        }
        return new BtyPerformanceMonthInformation();
    }

    @Override
    public LayuiPageInfo findPage(BtyPerformanceMonthInformationPageListParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPage(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public Map<String,String> rejectMd(BtyPerformanceMonthInformationPageListParam param) {
        //todo 判断是否在绩效时间内
        Map<String, String> mapValid = this.btyPerformanceMonthCheckService.getPerformanceDay();
        if(mapValid.get("pageValid").equals("1")){
            mapValid.put("pageInfo"," 当前时间不允许做绩效, 每月["+ mapValid.get("performanceDay")+"]允许绩效提交。");
            return mapValid;
        }
        //todo 给她一个上个月
        Map<String,String> mapLastMonth = this.btyPerformanceMonthCheckService.getPerformanceDay();
        param.setMonth(mapLastMonth.get("lastYearMonth"));

        //todo 根据店名，妖码，上个月日期更改
        Map<String, String> map = new HashMap<String, String>();
        Boolean flag = this.baseMapper.updateByYm(param);
        if(flag){
            map.put("flag","true");
            map.put("message","成功。");
            map.put("data","");
            return map;
        }

        map.put("flag","false");
        map.put("message","驳回失败，请确认门店信息。");
        map.put("data","");
        return map;
    }

    @Override
    public Map<String, String> getShopCount(BtyPerformanceMonthInformationPageListParam param) {

        // TODO: 2022/2/17 初始化数据
        Map<String, String> map = new HashMap<String, String>();
        //初值：总门店数，有绩效，无绩效，已提交，未提交
        map.put("totalMd","");//门店总数
        map.put("performanceMd","");//有绩效
        map.put("notperformanceMd","");//无绩效
        map.put("submitMd","");//已提交待审核
        map.put("notCreateMd","");//未创建未提交
        map.put("createMd","");//已创建未提交
        map.put("reject","");//已驳回
        map.put("pass","");//营运经理审核通过

        // todo 给它个做绩效的时间yyyyMM格式
        Map<String,String> mapTime = this.btyPerformanceMonthCheckService.getPerformanceDay();
        param.setMonth(mapTime.get("lastYearMonth"));



        //查询门店总数
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.total(pageContext, param);
        map.put("totalMd",String.valueOf(LayuiPageFactory.createPageInfo(page).getCount()));

        //查询有绩效的店的个数
        Page pageContext1 = getPageContext();
        IPage page1 = this.baseMapper.PerformanceMd(pageContext1, param);
        map.put("performanceMd",String.valueOf(LayuiPageFactory.createPageInfo(page1).getCount()));

        //查询无绩效的店的个数
        Page pageContext2 = getPageContext();
        IPage page2 = this.baseMapper.NotperformanceMd(pageContext2, param);
        map.put("notperformanceMd",String.valueOf(LayuiPageFactory.createPageInfo(page2).getCount()));

        //查询已提交的店的个数
        Page pageContext3 = getPageContext();
        IPage page3 = this.baseMapper.SubmitMd(pageContext3, param);
        map.put("submitMd",String.valueOf(LayuiPageFactory.createPageInfo(page3).getCount()));

        //查询未创建未提交的店的个数
        Page pageContext4 = getPageContext();
        IPage page4 = this.baseMapper.NotCreateMd(pageContext4, param);
        map.put("notCreateMd",String.valueOf(LayuiPageFactory.createPageInfo(page4).getCount()));

        //查询已创建未提交的店的个数
        Page pageContext6 = getPageContext();
        IPage page6 = this.baseMapper.createMd(pageContext6, param);
        map.put("createMd",String.valueOf(LayuiPageFactory.createPageInfo(page6).getCount()));

        //查询驳回的店的个数
        Page pageContext5 = getPageContext();
        IPage page5 = this.baseMapper.Reject(pageContext5, param);
        map.put("reject",String.valueOf(LayuiPageFactory.createPageInfo(page5).getCount()));

        //查询营运经理审核通过的店的个数
        Page pageContext7 = getPageContext();
        IPage page7 = this.baseMapper.pass(pageContext7, param);
        map.put("pass",String.valueOf(LayuiPageFactory.createPageInfo(page7).getCount()));

        return map;
    }

    @Override
    public ResponseEntity<byte[]> exportList(HttpServletRequest request, HttpServletResponse response, BtyPerformanceMonthInformationPageListParam param) {
        try {
            logger.info(">>>>>>>>>>绩效导出excel>>>>>>>>>>");
            BaseFrontController baseFrontController = new BaseFrontController();
            //TODO-1 获取查询结果
            List<BtyPerformanceSelectResult> resultList = this.baseMapper.customPage(param);
            return baseFrontController.buildResponseEntity(performanceExport(resultList, param), "绩效表.xls");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(">>>>>>>>>>绩效表-导出excel 异常，原因为：" + e.getMessage());
        }
        return null;
    }



    private InputStream performanceExport(List<BtyPerformanceSelectResult> list, BtyPerformanceMonthInformationPageListParam param) {
        logger.info(">>>>>>>>>>>>>>>>>>>>开始进入导出方法>>>>>>>>>>");
        ByteArrayOutputStream output = null;
        InputStream inputStream1 = null;
        // 保留1000条数据在内存中
        SXSSFWorkbook wb = new SXSSFWorkbook(1000);
        SXSSFSheet sheet = wb.createSheet();
        // 设置报表头样式cell样式
        CellStyle header = ExcelFormatUtil.headSytle(wb);
        // 报表体样式
        CellStyle content = ExcelFormatUtil.contentStyle(wb);
        //TODO-2 每一列字段名
        String[] titles = new String[]{"序号", "店名", "妖码", "营运经理", "督导", "姓名", "职位", "占比", "银行卡","绩效状态","提交状态","绩效月份"};
        // 字段名所在表格的宽度，数量应与列字段名数量一致
        int[] ints = new int[]{5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,5000,5000,5000};

        //TODO-3 设置总标题内容，没有可略过

        //TODO-4 设置内容标题
        //内容的标题所在行
        int concentitleStartRow = 1;
        //设置表头样式
        ExcelFormatUtil.initContentTitleEX(sheet, header, concentitleStartRow, titles, ints);
        logger.info(">>>>>>>>>>>>>>>>>>>>表头样式设置完成>>>>>>>>>>");
        //TODO-5 从第contentStartRow行开始为内容数据
        int contentStartRow = concentitleStartRow + 1;
        if (list != null && list.size() > 0) {
            int hangInx = 1;
            logger.info(">>>>>>>>>>>>>>>>>>>>开始遍历数据组装单元格内容>>>>>>>>>>");
            for (int i = 0; i < list.size(); i++) {
                BtyPerformanceSelectResult result = list.get(i);
                SXSSFRow row = sheet.createRow(contentStartRow + i - 1);
                int j = 0;
                // 1.序号
                SXSSFCell cell = row.createCell(j++);
                ExcelFormatUtil.setCellVal(hangInx, content, cell);
                //2.店名
                cell = row.createCell(j++);
                ExcelFormatUtil.setCellVal(result.getDm(), content, cell);
                //3.妖码
                cell = row.createCell(j++);
                ExcelFormatUtil.setCellVal(result.getYaoma(), content, cell);
                //4.营运经理
                cell = row.createCell(j++);
                ExcelFormatUtil.setCellVal(result.getYyjl(), content, cell);
                //5.督导
                cell = row.createCell(j++);
                ExcelFormatUtil.setCellVal(result.getDd(), content, cell);
                //6.姓名
                cell = row.createCell(j++);
                ExcelFormatUtil.setCellVal(result.getXm(), content, cell);

                //7.姓名
                cell = row.createCell(j++);
                ExcelFormatUtil.setCellVal(result.getXm(), content, cell);

                //8.占比
                cell = row.createCell(j++);
                ExcelFormatUtil.setCellVal(result.getRatio(), content, cell);

                //9.银行卡
                cell = row.createCell(j++);
                ExcelFormatUtil.setCellVal(result.getYhk(), content, cell);
                //10.绩效状态
                cell = row.createCell(j++);

                String jxStatus = "";
                    //纯利=0，无；纯利<0,无；纯利>0，有；
                if (result.getCl().compareTo(BigDecimal.ZERO) == 0) {
                    jxStatus = "无";
                } else if (result.getCl().compareTo(BigDecimal.ZERO) == 1) {
                    jxStatus = "有";
                } else if (result.getCl().compareTo(BigDecimal.ZERO) == -1) {
                    jxStatus = "无";
                }
                ExcelFormatUtil.setCellVal(jxStatus, content, cell);

                //11.提交状态
                cell = row.createCell(j++);

                String checkStatus = "";
                //提交状态 0未提交；1已提交；2已驳回
                    if (ToolUtil.isEmpty(result.getCheckStatus())){
                        checkStatus = "未创建";
                    } else if (result.getCheckStatus().equals("0")) {
                        checkStatus = "已创建未提交";
                    } else if (result.getCheckStatus().equals("1")) {
                        checkStatus = "待审核";
                    } else if (result.getCheckStatus().equals("2")) {
                        checkStatus = "已驳回";
                    }else if (result.getCheckStatus().equals("3")){
                        checkStatus = "已通过";
                    }

                ExcelFormatUtil.setCellVal(checkStatus, content, cell);
                //12.绩效月份
                cell = row.createCell(j++);
                StringBuffer sb=new StringBuffer();
                if (!ObjectUtil.isEmpty(result.getMonth())) {
                    sb.append(result.getMonth()).insert(4,'-');
                }
                ExcelFormatUtil.setCellVal(sb, content, cell);
                hangInx = hangInx + 1;
            }
            logger.info(">>>>>>>>>>>>>>>>>>>>结束遍历数据组装单元格内容>>>>>>>>>>");
        }
        try {
            output = new ByteArrayOutputStream();
            wb.write(output);
            inputStream1 = new ByteArrayInputStream(output.toByteArray());
            output.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (output != null) {
                    output.close();
                    if (inputStream1 != null) {
                        inputStream1.close();
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return inputStream1;
    }

    private Serializable getKey(BtyPerformanceMonthInformationParam param) {
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyPerformanceMonthInformation getOldEntity(BtyPerformanceMonthInformationParam param) {
        return this.getById(getKey(param));
    }

    private BtyPerformanceMonthInformation getEntity(BtyPerformanceMonthInformationParam param) {
        BtyPerformanceMonthInformation entity = new BtyPerformanceMonthInformation();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
